home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2 Examples.sit
/
Raven 1.2 Examples
/
Quill
/
Source
/
ViewDecorations.cpp
< prev
next >
Wrap
Text File
|
1997-05-11
|
9KB
|
345 lines
/*
* File: ViewDecorations.h
* Summary: Adorners and behaviors used in the view editor.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones.
* For conditions of distribution and use, see copyright notice in ZTypes.h
*
* Change History (most recent first):
*
* <-> 8/26/96 JDJ Created
*/
#include "ViewDecorations.h"
#include <LowMem.h>
#include <ZQDShapes.h>
#include <ZQuickDrawUtils.h>
#include <ZView.h>
#include "ViewCommands.h"
#include "ViewTrackers.h"
// ===================================================================================
// class COutlineAdorner
// ===================================================================================
//---------------------------------------------------------------
//
// COutlineAdorner::~COutlineAdorner
//
//---------------------------------------------------------------
COutlineAdorner::~COutlineAdorner()
{
}
//---------------------------------------------------------------
//
// COutlineAdorner::COutlineAdorner
//
//---------------------------------------------------------------
COutlineAdorner::COutlineAdorner() : TAdorner("COutlineAdorner", kNonPersistant)
{
}
//---------------------------------------------------------------
//
// COutlineAdorner::GetExtent
//
//---------------------------------------------------------------
TRect COutlineAdorner::GetExtent() const
{
TRect extent = this->GetOwner()->GetExtent();
extent.Inset(-1, -1);
return extent;
}
//---------------------------------------------------------------
//
// COutlineAdorner::OnDraw
//
//---------------------------------------------------------------
void COutlineAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
{
#if 1
TRegion oldClip = canvas.GetClip();
canvas.SetClip(extent);
TRectShape::Frame(canvas, extent, GetGray());
canvas.SetClip(oldClip);
#else
TRectShape::Frame(canvas, extent, GetGray());
TRegion clip = canvas.GetClip();
TRect outer = extent;
TRect inner = extent;
inner.Inset(1, 1);
clip -= TRegion(outer) - TRegion(inner);
canvas.SetClip(clip); // don't let the pane draw over our handles
#endif
}
#pragma mark -
// ===================================================================================
// class CHandleAdorner
// ===================================================================================
//---------------------------------------------------------------
//
// CHandleAdorner::~CHandleAdorner
//
//---------------------------------------------------------------
CHandleAdorner::~CHandleAdorner()
{
}
//---------------------------------------------------------------
//
// CHandleAdorner::CHandleAdorner
//
//---------------------------------------------------------------
CHandleAdorner::CHandleAdorner() : TAdorner("CHandleAdorner", kNonPersistant)
{
}
//---------------------------------------------------------------
//
// CHandleAdorner::OnDraw
//
//---------------------------------------------------------------
void CHandleAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
{
TRGBColor color;
LMGetHiliteRGB(&color);
TRegion clip = canvas.GetClip();
TRect handle = extent;
handle.right = handle.left + kHandleSize;
handle.bottom = handle.top + kHandleSize;
clip -= handle;
TRectShape::Fill(canvas, handle, color);
handle = extent;
handle.left = handle.right - kHandleSize;
handle.bottom = handle.top + kHandleSize;
clip -= handle;
TRectShape::Fill(canvas, handle, color);
handle = extent;
handle.right = handle.left + kHandleSize;
handle.top = handle.bottom - kHandleSize;
clip -= handle;
TRectShape::Fill(canvas, handle, color);
handle = extent;
handle.left = handle.right - kHandleSize;
handle.top = handle.bottom - kHandleSize;
clip -= handle;
TRectShape::Fill(canvas, handle, color);
canvas.SetClip(clip); // don't let the pane draw over our handles
}
#pragma mark -
// ===================================================================================
// class CNameAdorner
// ===================================================================================
//---------------------------------------------------------------
//
// CNameAdorner::~CNameAdorner
//
//---------------------------------------------------------------
CNameAdorner::~CNameAdorner()
{
}
//---------------------------------------------------------------
//
// CNameAdorner::CNameAdorner
//
//---------------------------------------------------------------
CNameAdorner::CNameAdorner(const string& name) : TAdorner(name, kNonPersistant), mTraits(200)
{
mBackColor = TRGBColor(64000, 45824, 39936); // ・・・ハload from a resource?
}
//---------------------------------------------------------------
//
// CNameAdorner::GetExtent
//
//---------------------------------------------------------------
TRect CNameAdorner::GetExtent() const
{
string text = this->GetText();
return this->GetTextBox(text);
}
//---------------------------------------------------------------
//
// CNameAdorner::GetTextBox
//
//---------------------------------------------------------------
TRect CNameAdorner::GetTextBox(const string& text) const
{
TSize size = mTraits.GetStringSize(text);
TRect box = Inherited::GetExtent();
box.bottom = box.top;
box.top = box.bottom - size.height;
STextTrait traits = mTraits.GetTraits();
if (traits.justification == teFlushLeft)
box.right = box.left + size.width;
else if (traits.justification == teFlushRight)
box.left = box.right - size.width;
// If the box is outside the superView's extent move it into
// the pane.
if (TPane* owner = dynamic_cast<TPane*>(this->GetOwner())) {
TView* superView = owner->GetSuperView();
if (superView != nil && !superView->GetExtent().Contains(box + owner->GetLocation()))
box += TPoint(0, size.height);
}
return box;
}
//---------------------------------------------------------------
//
// CNameAdorner::OnDraw
//
//---------------------------------------------------------------
void CNameAdorner::OnDraw(TCanvas& canvas, const TRect& extent)
{
#pragma unused(extent)
TRegion oldClip = canvas.GetClip();
string text = this->GetText();
TRect box = this->GetTextBox(text);
canvas.SetClip(box);
TRectShape::Fill(canvas, box, mBackColor);
TTextShape::Draw(canvas, text, box, mTraits);
oldClip -= box;
canvas.SetClip(oldClip);
}
#pragma mark -
// ===================================================================================
// class CPaneNameAdorner
// ===================================================================================
//---------------------------------------------------------------
//
// CPaneNameAdorner::~CPaneNameAdorner
//
//---------------------------------------------------------------
CPaneNameAdorner::~CPaneNameAdorner()
{
}
//---------------------------------------------------------------
//
// CPaneNameAdorner::CPaneNameAdorner
//
//---------------------------------------------------------------
CPaneNameAdorner::CPaneNameAdorner() : CNameAdorner("CPaneNameAdorner")
{
STextTrait traits = mTraits.GetTraits();
traits.justification = teFlushLeft;
mTraits = traits;
}
//---------------------------------------------------------------
//
// CPaneNameAdorner::GetText
//
//---------------------------------------------------------------
string CPaneNameAdorner::GetText() const
{
string text;
if (TPane* pane = dynamic_cast<TPane*>(this->GetOwner()))
text = pane->GetName();
return text;
}
#pragma mark -
// ===================================================================================
// class CClassNameAdorner
// ===================================================================================
//---------------------------------------------------------------
//
// CClassNameAdorner::~CClassNameAdorner
//
//---------------------------------------------------------------
CClassNameAdorner::~CClassNameAdorner()
{
}
//---------------------------------------------------------------
//
// CClassNameAdorner::CClassNameAdorner
//
//---------------------------------------------------------------
CClassNameAdorner::CClassNameAdorner() : CNameAdorner("CClassNameAdorner")
{
STextTrait traits = mTraits.GetTraits();
traits.justification = teFlushRight;
mTraits = traits;
}
//---------------------------------------------------------------
//
// CClassNameAdorner::GetText
//
//---------------------------------------------------------------
string CClassNameAdorner::GetText() const
{
string text;
if (MReanimatable* zombie = dynamic_cast<MReanimatable*>(this->GetOwner()))
text = zombie->GetClassName();
else
text = typeid(*this->GetOwner()).name();
return text;
}